package org.ns.learn.rpc.register;

import org.apache.zookeeper.*;

import java.util.concurrent.CountDownLatch;

public class D {
    public static void main(String[] args) throws  Exception{
        CountDownLatch connectAwait = new CountDownLatch(1);
        ZooKeeper zk = new ZooKeeper("127.0.0.1:2181", 10000, new Watcher() {
            @Override
            public void process(WatchedEvent watchedEvent) {
                System.out.println(watchedEvent.getState());
                if (watchedEvent.getState() == Event.KeeperState.SyncConnected) {
                    connectAwait.countDown();
                }
            }
        });
        connectAwait.await();
        String path = "/abc";
        try {
            zk.create(path, "ok".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        } catch (KeeperException.NodeExistsException e) {
            byte[] data = zk.getData(path,false, null);
            System.out.println(new String(data , "UTF-8"));
        }
        System.out.println("asdasd");
    }
}
